package favorite.controller;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestHeader;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import common.model.result.Result;
import favorite.service.IFavoriteService;

@RestController
@RequestMapping("/favorite")
public class FavoriteController {

    @Autowired
    private IFavoriteService favoriteService;

    //判断当前商品是否已经收藏
    @PostMapping("/isFavorite")
    public Result idFavorite(@RequestHeader Long uid, @RequestParam Long spuId){
        return favoriteService.isFavorite(uid,spuId);
    }

    //获取用户收藏表
    @GetMapping("/list")
    public Result list(@RequestHeader Long uid) {
        return favoriteService.findListByUid(uid);
    }

    //添加到收藏
    @PostMapping("/add")
    public Result add(@RequestHeader Long uid, @RequestParam Long spuId){
        return favoriteService.addFavorite(uid,spuId);
    }

    // //查询当前商品列表是否已收藏收藏
    // @GetMapping("/isFavoriteList")
    // public Result isFavoriteList(@RequestHeader Long uid, @RequestBody List<Long> spuIds, @RequestParam Integer page){
    //     return favoriteService.findGoodsIsFavorite(uid,spuIds,page);
    // };

    //取消收藏
    @PostMapping("/cancel")
    public Result cancel(@RequestHeader Long uid, @RequestParam Long spuId){
        return favoriteService.cancelFavorite(uid,spuId);
    }
}
